﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace DuAnNH
{
    class Cls_ThucDon
    {
        public static DataTable LayDSThucDon(string maloai)
        {
            try
            {
                string sql = "DanhSachTD_LoaiTD_2 '" + maloai + "'";
                //string sql = "select MaThucDon as 'Mã Thực Đơn',TenThucDon as 'Tên Thực Đơn',Gia as 'Giá' from ChiTietThucDon where MaLoai='" + maloai + "'";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static DataTable LayDSTD(string TenTD)
        {
            try
            {
                string sql = "Select * From ChiTietThucDon where TenThucDon=N'" + TenTD + "'";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static DataTable LayDSMaLoaiThucDon()
        {
            try
            {
                string sql = "Select * From LoaiThucDon";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static bool ThemTD(string ML, string TenTD, string Gia)
        {
            try
            {
                string str = string.Format("INSERT INTO ChiTietThucDon VALUES('{0}',N'{1}',{2})", ML, TenTD, Gia);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool XoaTD(string MaTD)
        {
            try
            {
                string str = string.Format("DELETE FROM ChiTietThucDon where MaThucDon='{0}'",MaTD);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Update_TD(string MaTD, string TenTD, string Gia)
        {
            try
            {
                string str = string.Format("UPDATE ChiTietThucDon SET TenThucDon=N'{0}',Gia='{1}' WHERE MaThucDon='{2}'", TenTD, Gia, MaTD);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static DataTable ThucDon_Ban(string MB)
        {
            try
            {
                string sql = string.Format("Select * FROM ChiTietHoaDon WHERE MaBan='{0}'", MB);
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }

        public static bool LuuHD(string MB, string TT)
        {
            try
            {
                //string str = "INSERT INTO HoaDon(ThoiGianLap,MaBan,TongTien) VALUES(getdate()," + Convert.ToInt32(MB) + "," + Convert.ToInt32(TT) + ")";
                string str = "Pro_LuuHoaDon '" + MB + "','" + TT + "'";
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool LuuCTHD(string SoHD,string MB, string MaTD,string TenTD, string Gia, string SL, string Tien)
        {
            try
            {
                string str = string.Format("INSERT INTO ChiTietHoaDon VALUES('{0}','{1}','{2}',N'{3}','{4}','{5}','{6}')",SoHD,MB, MaTD, TenTD, Gia, SL, Tien);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Update_TTBan(string SoHD)
        {
            try
            {
                string str = string.Format("Update_TTBan '" + SoHD + "'");
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Update_CTHD1(string MB, string MaTD, string TenTD, string Gia, string SL, string Tien)
        {
            try
            {
                string str = string.Format("INSERT INTO ChiTietHoaDon VALUES('{0}','{1}',N'{2}','{3}','{4}','{5}')", MB, MaTD, TenTD, Gia, SL, Tien);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool Update_CTHD(string MB, string MaTD, string SL, string Tien)
        {
            try
            {
                string str = string.Format("UPDATE ChiTietHoaDon SET SoLuong='{0}',Tien='{1}' WHERE MaBan='{2}' AND MaThucDon='{3}'", SL, Tien, MB, MaTD);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
